<?php

class SeniorController extends Zend_Controller_Action
{

    private $_redirector = null;
    
    private $_courses_page_limit        = 10;
    private $_announcements_page_limit  = 10;
    private $_books_page_limit          = 10;
    private $_chapters_page_limit       = 10;
    private $_articles_page_limit       = 10;
    
    
    public function init()
    {
        $this->_redirector = $this->_helper->getHelper('Redirector');
        $this->stylesBase  = $this->view->baseUrl() . '/styles/';
    }
    
    /**
     * This will validate our session and the requested action;
     */
    public function preDispatch()
    {
        // Check our identity
        if(Zend_Auth::getInstance()->hasIdentity())
        {
            // Check the requestion action
            switch ( $this->getRequest()->getActionName())
            {
                case 'index':
                case 'search':
                case 'edit':
                case 'delete':
                case 'follow':
                case 'stopfollow':
                case 'ajaxrequest':
                case 'view':
                    // -- These actions are allowed, nothing to do -- //
                    break;
                default:
                    // -- Invalid action requested, refer to homepage -- //
                    $this->_helper->redirector('index', 'index');
                    break;
            }
        }
        else
        {
            // -- No session, refer to loginpage -- //
            $this->_helper->redirector('login', 'user');
        }
    }
    
    /**
     * This action will handle all ajax-requests
     */
   public function ajaxrequestAction()
    {
        // Disable the layout
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        // Get current user
        $user   = Zend_Auth::getInstance()->getStorage()->read();
        
        // These are default pager variables
        $current_page   = (string)$this->getRequest()->getParam('p');
        $pager_base     = $this->getRequest()->getBaseUrl()."/senior/index/";
        
        // Get the request and do something accordingly
        $request  = (string)$this->getRequest()->getParam('req');
        switch($request)
        {
            case "pagecourses":
                $pager_var      = "crp";
                $html[]         = $this->_loopPartial('senior-block-course', $this->_getCoursesByAuthorId($user->Id, $current_page, $this->_courses_page_limit), array('user' => $user));
                $html[]         = $this->_fetchPager($current_page, ($this->_countCoursesByAuthorId($user->Id)/$this->_courses_page_limit), $pager_base, $pager_var);
                $result         = implode("\n", $html);
                break;
            case "pageannounces":
                $course_id      = (string)$this->getRequest()->getParam('id');
                $pager_var      = "anp";
                $html[]         = $this->_loopPartial('senior-block-announcement', $this->_getAnnouncementByAuthorId($user->Id, $current_page, $this->_books_page_limit));
                $html[]         = $this->_fetchPager($current_page, ($this->_countAnnouncementsByAuthorId($user->Id)/$this->_books_page_limit), $pager_base, $pager_var);
                $result         = implode("\n", $html);
                break;
            case "pagebooks":
                $course_id      = (string)$this->getRequest()->getParam('id');
                $pager_var      = "bkp";
                $html[]         = $this->_loopPartial('senior-block-book', $this->_getBooksByAuthorId($user->Id, $current_page, $this->_announcements_page_limit));
                $html[]         = $this->_fetchPager($current_page, ($this->_countBooksByAuthorId($user->Id)/$this->_announcements_page_limit), $pager_base, $pager_var);
                $result         = implode("\n", $html);
                break;
            case "pagechapters":
                $pager_var      = "chp";
                $html[]         = $this->_loopPartial('senior-block-chapter', $this->_getChaptersByAuthorId($user->Id, $current_page, $this->_chapters_page_limit), array('user' => $user));
                $html[]         = $this->_fetchPager($current_page, ($this->_countChaptersByAuthorId($user->Id)/$this->_chapters_page_limit), $pager_base, $pager_var);
                $result         = implode("\n", $html);
                break;
            case "pagearticles":
                $pager_var      = "arp";
                $html[]         = $this->_loopPartial('senior-block-article', $this->_getArticlesByAuthorId($user->Id, $current_page, $this->_articles_page_limit), array('user' => $user));
                $html[]         = $this->_fetchPager($current_page, ($this->_countArticlesByAuthorId($user->Id)/$this->_articles_page_limit), $pager_base, $pager_var);
                $result         = implode("\n", $html);
                break;
            default:
                $result = false;
                break;
        }
        
        // output result
        echo $result; 
    }

    /**
     * This is the main action.
     * It will display the All courses, My courses and New courses page-tabs
     */
    public function indexAction()
    {
        // Set up the view
        $view   = $this->_getView('Courses');
        // AJAX Search field
        $request = $this->getRequest();
        // Get the logged in User-object, and get other 
        $user   = Zend_Auth::getInstance()->getStorage()->read();
        // Pass some variables to our view
        $view->user     = $user;
        // Pager variables
        $pager_base     = $this->getRequest()->getBaseUrl()."/senior/index/";
        
        #### Set ALL COURSES BY AUTHOR block
        // Set search field
        $search_courses         = $this->_getSearchForm('course', 'tabs-1');
        $view->search_courses   = $search_courses;
        $crse_count             = $this->_countCoursesByAuthorId($user->Id);
        if($crse_count > 0)
        {
            //If post, validate the search request
            if($request->isPost() && $search_courses->isValid($request->getPost()))
            {
                $course_name        = $search_courses->getValue('srch_course');                                                
                $view->crse_partial = $this->_loopPartial('senior-block-course', $this->_getCourseByNameAndAuthorId($course_name, $user->Id), array('user' => $user));
                $view->crse_pager   = null;
            }            
            else
            {
                $crse_pager_var     = "crp";
                $crse_current_page  = (string)$this->getRequest()->getParam($crse_pager_var);
                $crse_current_page  = ($crse_current_page > 0 ? $crse_current_page : 1);
                $view->crse_partial = $this->_loopPartial('senior-block-course', $this->_getCoursesByAuthorId($user->Id, $crse_current_page, $this->_courses_page_limit), array('user' => $user));
                $view->crse_pager   = $this->_fetchPager($crse_current_page, ($crse_count/$this->_courses_page_limit), $pager_base, $crse_pager_var);
            }     
        }
        else
        {
            $view->crse_partial = "<p>There are no current courses added to our website. Please check again soon.</p>";
            $view->crse_pager   = null;
        }
        
        ####    Set ALL ANNOUNCEMENTS BY AUTHOR block
        // search field
        $search_announcements       = $this->_getSearchForm('announcement', 'tabs-2');
        $view->search_announcements = $search_announcements;
        $nncmnts_count              = $this->_countAnnouncementsByAuthorId($user->Id);
        if($nncmnts_count > 0)
        {
            //If post, validate the search request
            if($request->isPost() && $search_announcements->isValid( $request->getPost()))
            {
                $announcement_name     = $search_announcements->getValue('srch_announcement');                                                
                $view->nncmnts_partial = $this->_loopPartial('senior-block-announcement', $this->_getAnnouncementByNameAndAuthorId($announcement_name, $user->Id), array('user' => $user));
                $view->nncmnts_pager   = null;
            }            
            else
            {
                $nncmnts_pager_var     = "anp";
                $nncmnts_current_page  = (string)$this->getRequest()->getParam($nncmnts_pager_var);
                $nncmnts_current_page  = ($nncmnts_current_page > 0 ? $nncmnts_current_page : 1);
                $view->nncmnts_partial = $this->_loopPartial('senior-block-announcement', $this->_getAnnouncementByAuthorId($user->Id, $nncmnts_current_page, $this->_announcements_page_limit), array('user' => $user));
                $view->nncmnts_pager   = $this->_fetchPager($nncmnts_current_page, ($nncmnts_count/$this->_announcements_page_limit), $pager_base, $nncmnts_pager_var);
            }  
        }
        else
        {
            $view->nncmnts_partial = $view->partial('partials/add-course.phtml', array());
            $view->nncmnts_pager   = null;
        }
        
        ####    Set ALL BOOKS BY AUTHOR block
        // Set search field
        $search_books       = $this->_getSearchForm('book', 'tabs-3');
        $view->search_books = $search_books;
        $bks_count          = $this->_countBooksByAuthorId($user->Id);
        if($bks_count > 0)
        {
            //If post, validate the search request
            if($request->isPost() && $search_books->isValid( $request->getPost()))
            {
                $book_name   = $search_books->getValue('srch_book', 'tabs-3');                                                
                $view->bks_partial = $this->_loopPartial('senior-block-book', $this->_getBookByNameAndAuthorId($book_name, $user->Id), array('user' => $user));
                $view->bks_pager   = null;
            }            
            else
            {
                $bks_pager_var     = "bkp";
                $bks_current_page  = (string)$this->getRequest()->getParam($bks_pager_var);
                $bks_current_page  = ($bks_current_page > 0 ? $bks_current_page : 1);
                $view->bks_partial = $this->_loopPartial('senior-block-book', $this->_getBooksByAuthorId($user->Id, $bks_current_page, $this->_books_page_limit), array('user' => $user));
                $view->bks_pager   = $this->_fetchPager($bks_current_page, ($bks_count/$this->_books_page_limit), $pager_base, $bks_pager_var);
            }  
        }
        else
        {
            $view->bks_partial = "<p>You have not added any books yet.</p>";
            $view->bks_pager   = null;
        }
        
        ####    Set ALL CHAPTERS BY AUTHOR block
        // search field
        $search_chapters        = $this->_getSearchForm('chapter', 'tabs-4');
        $view->search_chapters  = $search_chapters;
        $chptr_count            = $this->_countChaptersByAuthorId($user->Id);
        if($chptr_count > 0)
        {
            //If post, validate the search request
            if($request->isPost() && $search_chapters->isValid( $request->getPost()))
            {
                $chapter_name        = $search_chapters->getValue('srch_chapter');                                                
                $view->chptr_partial = $this->_loopPartial('senior-block-chapter', $this->_getChapterByNameAndAuthorId($chapter_name, $user->Id), array('user' => $user));
                $view->chptr_pager   = null;
            }            
            else
            {
                $chptr_pager_var     = "chp";
                $chptr_current_page  = (string)$this->getRequest()->getParam($chptr_pager_var);
                $rccr_current_page   = ($chptr_current_page > 0 ? $chptr_current_page : 1);
                $view->chptr_partial = $this->_loopPartial('senior-block-chapter', $this->_getChaptersByAuthorId($user->Id, $chptr_current_page, $this->_chapters_page_limit), array('user' => $user));
                $view->chptr_pager   = $this->_fetchPager($chptr_current_page, ($chptr_count/$this->_chapters_page_limit), $pager_base, $chptr_pager_var);
            }  
        }
        else
        {
            $view->chptr_partial = "<p>You did not make any chapters yet.</p>";
            $view->chptr_pager   = null;
        }
        
        #### Set ALL ARTICLES BY AUTHOR block
        // search field
        $search_article         = $this->_getSearchForm('article', 'tabs-5');
        $view->search_article   = $search_article;
        $rtcl_count         = $this->_countArticlesByAuthorId($user->Id);
        if($rtcl_count > 0)
        {
            //If post, validate the search request
            if($request->isPost() && $search_article->isValid( $request->getPost()))
            {
                $book_name   = $search_article->getValue('srch_article');                                                
                $view->rtcl_partial = $this->_loopPartial('senior-block-article', $this->_getArticleByNameAndAuthorId($book_name, $user->Id), array('user' => $user));
                $view->rtcl_pager   = null;
            }            
            else
            {
                $rtcl_pager_var     = "arp";
                $rtcl_current_page  = (string)$this->getRequest()->getParam($rtcl_pager_var);
                $rtcl_current_page  = ($rtcl_current_page > 0 ? $rtcl_current_page : 1);
                $view->rtcl_partial = $this->_loopPartial('senior-block-article', $this->_getArticlesByAuthorId($user->Id, $rtcl_current_page, $this->_articles_page_limit), array('user' => $user));
                $view->rtcl_pager   = $this->_fetchPager($rtcl_current_page, ($rtcl_count/$this->_articles_page_limit), $pager_base, $rtcl_pager_var);
            }  
        }
        else
        {
            $view->rtcl_partial = "<p>You did not make any articles yet.</p>";
            $view->rtcl_pager   = null;
        }
    }    
    
    
    public function searchAction()
    {
        // Disable layout
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        // Get the logged in User-object, and get other 
        $user   = Zend_Auth::getInstance()->getStorage()->read();
        $type   = $this->_getParam('type');
        $term   = $this->_getParam('term');
        // Result storage
        $result  = array();
        // Fetch results by request
        //$result[] = "test: ".print_r($_REQUEST, true);
        switch($type)
        {
            case 'course':
                $objects = $this->_getCourseByNameAndAuthorId($term, $user->Id);
                if(count($objects) > 0)
                    foreach($objects as $object)
                        $result[] = $object->Name;
                break;
            case 'announcement':
                $objects = $this->_getAnnouncementByNameAndAuthorId($term, $user->Id);
                if(count($objects) > 0)
                    foreach($objects as $object)
                        $result[] = $object->Title;
                break;
            case 'book':
                $objects = $this->_getBookByNameAndAuthorId($term, $user->Id);
                if(count($objects) > 0)
                    foreach($objects as $object)
                        $result[] = $object->Title;
                break;
            case 'chapter':
                $objects = $this->_getChapterByNameAndAuthorId($term, $user->Id);
                if(count($objects) > 0)
                    foreach($objects as $object)
                        $result[] = $object->Name;
                break;
            case 'article':
                $objects = $this->_getArticleByNameAndAuthorId($term, $user->Id);
                if(count($objects) > 0)
                    foreach($objects as $object)
                        $result[] = $object->Name;
                break;
            
        }
        // output
        $this->_helper->json($result);
    }   
    
    
    /**
     * AJAX Autocomplete search form
     * 
     * @param $type_value   The value of the 'type' parameter
     * @param $tab_id       The ID-attribute of the tab you want to open
     * @param $controllor   The name of the controller
     * @param $action       The name of the action
     * @return ZendX_JQuery_Form
     */
    private function _getSearchForm($type_value, $tab_id='', $controller='senior', $action='search')
    {
        $tab_id     = (strlen($tab_id) ? '#'.$tab_id : '');
        $search_id  = 'srch_'.$type_value;
        $view       = $this->view;
        $form       = new ZendX_JQuery_Form(array(
            'action' => $this->view->baseUrl('senior/index').$tab_id,
            'method' => 'post',
            'id'     => 'form_'.$search_id,
            'class'  => 'ajax-search-form',
        ));
        $form->addElement('autocomplete', $search_id, array(
            'label'     =>'Name',
            'required'  => false,
            'filters'   => array('StringTrim'),
        ));
        $form->addElement('submit', 'search', array(
            'label'     => 'search',
        ));
        $form->getElement($search_id)->setJQueryParam('source', $view->baseUrl().'/'.$controller.'/'.$action.'/type/'.$type_value);
        return $form;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    /**
     * Fetch a course by its ID
     * 
     * @param integer $course_id
     * @return Array
     */
    private function _getCourseById($course_id)
    {
        $mapper = new Application_Model_CourseMapper();
        return $mapper->fetchById($course_id);
    }
    
    /**
     * Fetch a course by its name and authorId
     * 
     * @param integer $course_name
     * @return Array
     */
    private function _getCourseByNameAndAuthorId($course_name, $user_id)
    {
        $mapper = new Application_Model_CourseMapper();
        return $mapper->fetchByNameAndAuthorId($course_name, $user_id);
    }
    
    /**
     * Fetch a announcement by its name and authorId
     * 
     * @param integer $announcement_name
     * @return Array
     */
    private function _getAnnouncementByNameAndAuthorId($announcement_name, $author_id)
    {
        $mapper = new Application_Model_AnnouncementMapper();
        return $mapper->fetchByNameAndAuthorId($announcement_name, $author_id);
    }
    
    /**
     * Fetch a book by its name and authorId
     * 
     * @param integer $book_name
     * @return Array
     */
    private function _getBookByNameAndAuthorId($book_name, $author_id)
    {
        $mapper = new Application_Model_BookMapper();
        return $mapper->fetchByNameAndAuthorId($book_name, $author_id);
    }
    
    /**
     * Fetch a chapter by its name and authorId
     * 
     * @param integer $chapter_name
     * @return Array
     */
    private function _getChapterByNameAndAuthorId($chapter_name, $author_id)
    {
        $mapper = new Application_Model_ChapterMapper();
        return $mapper->fetchByNameAndAuthorId($chapter_name, $author_id);
    }
               
    /**
     * Fetch a book by its name and authorId
     * 
     * @param integer $book_name
     * @return Array
     */
    private function _getArticleByNameAndAuthorId($article_name, $author_id)
    {
        $mapper = new Application_Model_ArticleMapper();
        return $mapper->fetchByNameAndAuthorId($article_name, $author_id);
    }    
    
    
    /**
     * Get all announcements 
     *
     * @param integer $page_nr      If you wish to use paging, pass the page-number. To
     *                              disable paging, pass null as value (default) and 
     *                              return all rows.
     * @param integer $nr_results   The number of results per page, defaults to 10.
     * @return Array(Application_Model_Announcement)
     */
    private function _getAnnouncementByAuthorId($user_id, $page_nr = null, $nr_results = 0)
    {
        $mapper = new Application_Model_AnnouncementMapper();
        return $mapper->fetchByAuthorId($user_id, $page_nr, $nr_results);
    }    
    
    /**
     * Returns the number of courses for an author
     * 
     * @param integer $author_id
     * @return integer
     */
    private function _countCoursesByAuthorId($author_id)
    {
        $mapper = new Application_Model_CourseMapper();
        return $mapper->getCountByAuthorId($author_id);
    }
    
    /**
     * Get all courses for a user
     *
     * @param integer $user_id
     * @param integer $page_nr      If you wish to use paging, pass the page-number. To
     *                              disable paging, pass null as value (default) and 
     *                              return all rows.
     * @param integer $nr_results   The number of results per page, defaults to 10.
     * @return Array(Application_Model_Course)
     */
    /*private function _getCoursesByUserId($user_id, $page_nr = null, $nr_results = 0)
    {
        $mapper = new Application_Model_CourseMapper();
        return $mapper->fetchByUserId($user_id, $page_nr, $nr_results);
    }*/
    
    private function _getCoursesByAuthorId($user_id, $page_nr = null, $nr_results = 0)
    {
        $mapper = new Application_Model_CourseMapper();
        return $mapper->fetchByAuthorId($user_id, $page_nr, $nr_results);
    }
    
    /**
     * Returns the number of courses for this author
     * 
     * @param integer $author_id
     * @return integer
     */
    private function _countAnnouncementsByAuthorId($author_id)
    {
        $mapper = new Application_Model_AnnouncementMapper();        
        return $mapper->getCountByAuthorId($author_id);
    }
    
     /**
     * Get all books from author
     *
     * @param integer $page_nr      If you wish to use paging, pass the page-number. To
     *                              disable paging, pass null as value (default) and 
     *                              return all rows.
     * @param integer $nr_results   The number of results per page, defaults to 10.
     * @return Array(Application_Model_Book)
     */
    private function _getBooksByAuthorId($user_id, $page_nr = null, $nr_results = 0)
    {
        $mapper = new Application_Model_BookMapper();
        return $mapper->fetchByAuthorId($user_id, $page_nr, $nr_results);
    }
    
    /**
     * Returns the number of books of an author
     * 
     * @param integer $author_id         The author to fetch back to
     * @return integer
     */
    private function _countBooksByAuthorId($author_id)
    {
        $mapper = new Application_Model_BookMapper();
        return $mapper->getCountByAuthorId($author_id);
    }
    /**
     * Get all chapters from author
     *
     * @param integer $page_nr      If you wish to use paging, pass the page-number. To
     *                              disable paging, pass null as value (default) and 
     *                              return all rows.
     * @param integer $nr_results   The number of results per page, defaults to 10.
     * @return Array(Application_Model_Announcement)
     */
    
    private function _getChaptersByAuthorId($user_id, $page_nr = null, $nr_results = 0)
    {
        $mapper = new Application_Model_ChapterMapper();
        return $mapper->fetchByAuthorId($user_id, $page_nr, $nr_results);
    }
    
    /**
     * Returns the number of chapters of an author
     * 
     * @param integer $author_id         The author to fetch back to
     * @return integer
     */
    private function _countChaptersByAuthorId($author_id)
    {
        $mapper = new Application_Model_ChapterMapper();
        return $mapper->getCountByAuthorId($author_id);
    }
    
    /**
     * Get all articles from author
     *
     * @param integer $page_nr      If you wish to use paging, pass the page-number. To
     *                              disable paging, pass null as value (default) and 
     *                              return all rows.
     * @param integer $nr_results   The number of results per page, defaults to 10.
     * @return Array(Application_Model_Article)
     */
    
    private function _getArticlesByAuthorId($user_id, $page_nr = null, $nr_results = 0)
    {
        $mapper = new Application_Model_ArticleMapper();
        return $mapper->fetchByAuthorId($user_id, $page_nr, $nr_results);
    }
    
    /**
     * Returns the number of articles of an author
     * 
     * @param integer $author_id         The author to fetch back to
     * @return integer
     */
    private function _countArticlesByAuthorId($author_id)
    {
        $mapper = new Application_Model_ArticleMapper();
        return $mapper->getCountByAuthorId($author_id);
    }
    
    /**
     * Get all announcements for a course
     *
     * @param integer $course_id
     * @param integer $page_nr      If you wish to use paging, pass the page-number. To
     *                              disable paging, pass null as value (default) and 
     *                              return all rows.
     * @param integer $nr_results   The number of results per page, defaults to 10.
     * @return Array(Application_Model_Course)
     */
    private function _getAnnouncementsByCourseId($course_id, $page_nr = null, $nr_results = 0)
    {
        $mapper = new Application_Model_AnnouncementMapper();
        return $mapper->fetchByCourseId($course_id, $page_nr, $nr_results);
    }
    
    /**
     * Get the number of announcements for this course
     * 
     * @param integer $course_id
     * @return integer
     */
    private function _countAnnouncementsByCourseId($course_id)
    {
        $mapper = new Application_Model_AnnouncementMapper();
        return $mapper->getCountByCourseId($course_id);
    }
    
    /**
     * Get all books for a course
     *
     * @param integer $course_id
     * @param integer $page_nr      If you wish to use paging, pass the page-number. To
     *                              disable paging, pass null as value (default) and 
     *                              return all rows.
     * @param integer $nr_results   The number of results per page, defaults to 10.
     * @return Array(Application_Model_Course)
     */
    private function _getBooksByCourseId($course_id, $page_nr = null, $nr_results = 0)
    {
        $mapper = new Application_Model_BookMapper();
        return $mapper->fetchByCourseId($course_id, $page_nr, $nr_results);
    }
    
    /**
     * Get the number of books for this course
     * 
     * @param integer $course_id
     * @return integer
     */
    private function _countBooksByCourseId($course_id)
    {
        $mapper = new Application_Model_BookMapper();
        return $mapper->getCountByCourseId($course_id);
    }
    
    /**
     * Add a course to a user's follow list
     * 
     * @param integer $course_id
     * @param integer $user_id 
     */
    private function _addCourseToFollowList($course_id, $user_id)
    {
        $mapper = new Application_Model_UserMapper();
        $mapper->addCourseToUser($course_id, $user_id);
    }
    
    /**
     * Add a course to a user's follow list
     * 
     * @param integer $course_id
     * @param integer $user_id 
     */
    private function _removeCourseFromFollowList($course_id, $user_id)
    {
        $mapper = new Application_Model_UserMapper();
        $mapper->deleteCourseFromUser($course_id, $user_id);
    }

    /**
     * Loops through a list of custom objects, passing each object to the partial.
     * The end result is a html-render of the all the partials.
     *
     * @param string $partial
     * @param Array $objects
     * @return string
     */
    private function _loopPartial($partial, $objects, $extravars=null)
    {
        $result = array();
        $count  = 0;
        if(count($objects))
        {
            foreach($objects as $object)
            {
                $count++;
                $vars       = array(
                    'object'    => $object,
                    'count'     => $count,
                );
                
                if(is_array($extravars))
                    $vars = array_merge($extravars, $vars);
                
                $result[]   = $this->_getView("")->partial('partials/'.$partial.'.phtml', $vars);
            }
        }
        
        return implode("\n", $result);
    }

    /**
     * Get the HTML pager for a list that requires pagination
     *
     * @param int $page_nr
     * @param int $total_pages
     * @param string $base_url
     * @param string $page_var
     * @return string 
     */
    private function _fetchPager($current_page, $total_pages, $base_url, $page_var)
    {
        $view   = $this->_getView("");
        $vars   = array(
            'cur_page'      => $current_page,
            'nr_of_pages'   => ceil($total_pages),
            'base_url'      => $base_url,
            'page_var'      => $page_var,
        );
        
        return $view->partial('partials/pager.phtml', $vars);
    }

    /**
     * This returns the view for this controller.
     *
     * @param string $title
     * @return Zend_View
     */
    private function _getView($title)
    {
        $view = $this->view;
        $view->title = $title;
        $view->headTitle($view->title, 'PREPEND');
        $view->headLink()->appendStylesheet($this->stylesBase . 'panel.css');

        return $view;
    }
}

